package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMenuMapper;
import com.atguigu.spzx.manager.service.SysRoleMenuService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {
    @Resource
    SysRoleMenuMapper sysRoleMenuMapper;
    @Override
    public void assignMenus2Role(List<Long> menuIds, Long roleId) {
        //1、删除roleId所有的菜单
        sysRoleMenuMapper.deleteMenusByRoleId(roleId);
        //2、如果菜单id不为空，分配菜单给角色
        if(CollectionUtils.isEmpty(menuIds)){
            return;
        }
        sysRoleMenuMapper.assignMenus2Role(menuIds , roleId);
    }
}
